package cz.via.facepalm.calendar;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;

public class EditProjectExpandableList extends ExpandableListActivity 
{
	String [] projects = new String[]{"Via Project", "Pal Project"};
	
	@SuppressWarnings("unchecked")
	public void onCreate(Bundle savedInstaceState)
	{					
		try
		{
			super.onCreate(savedInstaceState);
			setContentView(R.layout.editprojectexpladablelist);
			
			SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
				this,
				createGroupList(),              
				R.layout.plain_group_row,             
				new String[] { "Title" },  
				new int[] { R.id.row_title },
				createChildList(),              
				R.layout.editproject,             
				new String[] {"Title"},      
				new int[] { R.id.name}     
			);
			setListAdapter( expListAdapter );
		}
		catch(Exception e)
		{			
			System.out.println("Errr +++ "+ e.getMessage());
		}					
	}
		
	@SuppressWarnings("unchecked")
	private List createGroupList() 
	{
		ArrayList result = new ArrayList();
		for( int i = 0 ; i < projects.length ; ++i ) { 
			HashMap m = new HashMap();						
			m.put( "Title",projects[i]);
			result.add( m );
		}
		return (List)result;
   }
   
   @SuppressWarnings("unchecked")
   private List createChildList() {
	   
     ArrayList result = new ArrayList();
     for( int i = 0 ; i < projects.length ; ++i ) 
     { 
    	 ArrayList secList = new ArrayList();    	 
		 HashMap child = new HashMap();    		   
	     child.put( "Title", projects[i] );		         		  
	     secList.add( child );		     	    	 
    	 
    	 result.add( secList );
     }
     return (List)result;
   }
   
   public void  onContentChanged  () 
   {       
       super.onContentChanged();
       System.out.println("onContentChanged");
   }
      
   public boolean onChildClick( ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
       System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
       return true;
   }
	
	public void  onGroupExpand  (int groupPosition) 
	{
		try
		{
			System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);
		}
		catch(Exception e)
		{
			System.out.println(" groupPosition Errrr +++ " + e.getMessage());
		}
	}
}
